package com.example.tanloadpic;

import android.graphics.Bitmap;
import android.util.LruCache;

import static com.example.tanloadpic.utils.CommonUtils.stringToMd5;


public class memoryCachesImpl   implements MemoryCaches {

    public final LruCache<String, Bitmap> mMemoryCache;

    public memoryCachesImpl() {
        int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
        int cacheSize = maxMemory / 8;
        mMemoryCache = new LruCache<String, Bitmap>(cacheSize) {
            @Override
            protected int sizeOf(String key, Bitmap bitmap) {
                return bitmap.getRowBytes() * bitmap.getHeight() / 1024;
            }
        };

    }

    @Override
    public void put(String key, Bitmap bitmap) {
        mMemoryCache.put(key,bitmap);
    }

    @Override
    public Bitmap getBitmap(String key) {
        return mMemoryCache.get(key);
    }

    @Override
    public void clear() {
        mMemoryCache.evictAll();
    }


}
